//
//  CYBettingRandomNumber.m
//  CaiYun
//
//  Created by 今日信息科技 on 2017/8/3.
//  Copyright © 2017年 今日信息科技. All rights reserved.
//

#import "CYBettingRandomNumber.h"
#define String(a) [NSString stringWithFormat:@"%d",a]//int转string
#define Arr(a,b) [NSMutableArray arrayWithObjects:String(a),String(b),nil]//两个int类型，转换成数组
#define Arr_3(a,b,c) [NSMutableArray arrayWithObjects:String(a),String(b),String(c),nil]//三个int类型，转换成数组
#define random_same(minNum,maxNum,count1,count2) [self getRandomArr:minNum max:maxNum arrCount:count1 setCount:count2] //获取随机数组合，数组的集合之间允许有重复元素
#define random_different(minNum,maxNum,count,array) [self getRandomArr:minNum max:maxNum arrCount:count arrayOfSetCount:array]//获取随机数组合，数组的集合之间不允许有重复元素
#define DiPinCaiType 16
#define ShiYiXuanWuType 77
#define KuaiSanType 39
#define ShiShiLeType 101
#define ShiShiCaiType 2
#define PKShiType 27
@implementation CYBettingRandomNumber
//------------------------------------------------随机算法---------------------------------------------------------------------------------------------------------------------------------------------------------//

//机选号码
+ (NSMutableArray *)getRandomSource:(NSUInteger)played_group_id playedIdentifier:(NSString *)identifier cellArr:(NSMutableArray *)cellArr{
    //任选之类的玩法，（只要是不是所有cell都要选的）
    if ([@[@"ssc_z2_r2",@"ssc_5x_r3",@"ssc_z3_r3",@"ssc_z3_r6",@"ssc_5x_dw",@"ssc_2x_r2f",@"ssc_3x_r3f",@"ssc_dx_r4f",@"three_dxds_r2",@"three_3x_dw",@"ssc_11x5_dwd",@"bjpk10_dw",@"ssl_dwd_dwd",@"k3_2dx"] containsObject:identifier])
        return (NSMutableArray *)[self getRandomForSpecialIdentifier:identifier];
    
    NSMutableArray * random_selectArr;
    if(played_group_id == ShiShiCaiType)
        random_selectArr = [self getRandomArrForShiShiCai:identifier];
    else if (played_group_id == ShiYiXuanWuType)
        random_selectArr = [self getRandomArrForShiYiXuanWu:identifier];
    else if (played_group_id == PKShiType)
        random_selectArr = [self getRandomArrForPKShi:identifier];
    else if (played_group_id == DiPinCaiType)
        random_selectArr = [self getRandomArrForDiPinCai:identifier];
    else if (played_group_id == KuaiSanType)
        random_selectArr = [self getRandomArrForKuaiSan:identifier];
    else if (played_group_id == ShiShiLeType)
        random_selectArr = [self getRandomArrForShiShiLe:identifier];
    return [self dictionaryWithCellArr:cellArr array:random_selectArr];
}

//特殊的玩法的随机数，比如，时时彩，二星组选-任二组选复式
+ (NSArray *)getRandomForSpecialIdentifier:(NSString *)identifier{
    if ([@[@"ssc_z2_r2"] containsObject:identifier])
        return [self dictionaryWithWeiJiArr:[[self getRandomSet:0 max:4 setCount:2] allObjects] set:[self getRandomSet:0 max:9 setCount:2]];//字典key为位级的下标,value为随机的号码集合
    else if ([@[@"ssc_5x_r3"] containsObject:identifier])//时时彩-不定胆-任三一码
        return [self dictionaryWithWeiJiArr:[[self getRandomSet:0 max:4 setCount:3] allObjects] set:[self getRandomSet:0 max:9 setCount:1]];//字典key为位级的下标,value为随机的号码集合
    else if ([@[@"ssc_z3_r3"] containsObject:identifier])//时时彩-任选-任三组三
        return [self dictionaryWithWeiJiArr:[[self getRandomSet:0 max:4 setCount:3] allObjects] set:[self getRandomSet:0 max:9 setCount:2]];//字典key为位级的下标,value为随机的号码集合
    else if ([@[@"ssc_z3_r6"] containsObject:identifier])//时时彩-任选-任三组六
        return [self dictionaryWithWeiJiArr:[[self getRandomSet:0 max:4 setCount:3] allObjects] set:[self getRandomSet:0 max:9 setCount:3]];//字典key为位级的下标,value为随机的号码集合
    else if ([@[@"ssc_5x_dw"] containsObject:identifier])//时时彩-定位胆-五星定位胆
        return [self dictionaryWithRenXuan:0 max:4 cellCount:1 minNum:0 maxNum:9 numCount:1 identifier:identifier];
    else if ([@[@"ssc_2x_r2f"] containsObject:identifier])//时时彩-任选-任二直选复式
        return [self dictionaryWithRenXuan:0 max:4 cellCount:2 minNum:0 maxNum:9 numCount:1 identifier:identifier];
    else if ([@[@"ssc_3x_r3f"] containsObject:identifier])//时时彩-任选-任三直选复式
        return [self dictionaryWithRenXuan:0 max:4 cellCount:3 minNum:0 maxNum:9 numCount:1 identifier:identifier];
    else if ([@[@"ssc_dx_r4f"] containsObject:identifier])//时时彩-任选-任四直选复式
        return [self dictionaryWithRenXuan:0 max:4 cellCount:4 minNum:0 maxNum:9 numCount:1 identifier:identifier];
    else if ([@[@"three_dxds_r2"] containsObject:identifier])//福彩3D-大小单双-任二大小单双
        return [self dictionaryWithRenXuan:2 max:4 cellCount:2 minNum:0 maxNum:3 numCount:1 identifier:identifier];
    else if ([@[@"three_3x_dw",@"ssl_dwd_dwd"] containsObject:identifier])//福彩3D-定位胆-三星定位胆
        return [self dictionaryWithRenXuan:2 max:4 cellCount:1 minNum:0 maxNum:9 numCount:1 identifier:identifier];
    else if ([@[@"ssc_11x5_dwd"] containsObject:identifier])//时时彩-11选5-定位胆
        return [self dictionaryWithRenXuan:0 max:4 cellCount:1 minNum:1 maxNum:10 numCount:1 identifier:identifier];
    else if ([@[@"bjpk10_dw"] containsObject:identifier])//pk10-定位胆选-定位胆选
        return [self dictionaryWithRenXuan:0 max:9 cellCount:1 minNum:1 maxNum:10 numCount:1 identifier:identifier];
    else if ([@[@"k3_2dx"] containsObject:identifier])//快三-二同单选-二同号单选
        return [self dictionaryWithRenXuan:0 max:1 cellCount:2 minNum:1 maxNum:6 numCount:1 identifier:identifier];
    
    return nil;
}

+ (NSMutableArray *)getRandomArrForShiShiCai:(NSString *)identifier{
    if ([@[@"ssc",@"ssc_5x_dw"] containsObject:identifier])
        return random_same(0,9,5,1);//获取随机数组合，数组的集合之间允许有重复元素
    else if ([@[@"ssc_5x_z5_120"] containsObject:identifier])
        return random_same(0, 9, 1, 5);
    else if ([@[@"ssc_5x_z5_60"] containsObject:identifier])
        return random_different(0, 9, 2, Arr(1, 3));//获取随机数组合，数组的集合之间不允许有重复元素
    else if ([@[@"ssc_5x_z5_30"] containsObject:identifier])
        return random_different(0, 9, 2, Arr(2, 1));
    else if ([@[@"ssc_5x_z5_20",@"ssc_4x_z4_12"] containsObject:identifier])
        return random_different(0, 9, 2, Arr(1, 2));
    else if ([@[@"ssc_5x_z5_10", @"ssc_5x_z5_5",@"ssc_4x_z4_4"] containsObject:identifier])
        return random_different(0, 9, 2, Arr(1, 1));
    else if ([@[@"ssc_dx_q4f",@"ssc_dx_h4f"] containsObject:identifier])
        return random_same(0, 9, 4, 1);
    else if ([@[@"ssc_4x_z4_24"] containsObject:identifier])
        return random_same(0, 9, 1, 4);
    else if ([@[@"ssc_4x_z4_6",@"ssc_z3_q3",@"ssc_z3_z3",@"ssc_z2_f2",@"ssc_z2_r2",@"ssc_2x_qbdw",@"ssc_2x_hbdw",@"ssc_5x_2m_bdw",@"ssc_4x_2m_bdw"] containsObject:identifier])
        return random_same(0, 9, 1, 2);
    else if ([@[@"ssc_h3_kd",@"ssc_hz_h3",@"ssc_5x_q3",@"ssc_5x_z3",@"ssc_5x_h3",@"ssc_4x_1m_bdw",@"qwwf_yffs"] containsObject:identifier])
        return random_same(0, 9, 1, 1);
    else if ([@[@"ssc_3x_q3f",@"ssc_3x_z3fs",@"ssc_3x_h3f"] containsObject:identifier])
        return random_same(0, 9, 3, 1);
    else if ([@[@"ssc_ts_h3"] containsObject:identifier])
        return random_same(0, 2, 1, 1);
    else if ([@[@"ssc_z3_q6",@"ssc_z3_z6",@"ssc_5x_3m_bdw"] containsObject:identifier])
        return random_same(0, 9, 1, 3);
    else if ([@[@"ssc_2x_q2f",@"ssc_2x_h2f"] containsObject:identifier])
        return random_same(0, 9, 2, 1);
    else if ([@[@"ssc_q2_zhi_hz",@"ssc_h2_zhi_hz"] containsObject:identifier])
        return random_same(0, 18, 1, 1);
    else if ([@[@"ssc_qh2_zhu_hz",@"ssc_h2_zhu_hz"] containsObject:identifier])
        return random_same(1, 17, 1, 1);
    else if ([@[@"ssc_dxds_q2",@"ssc_dxds_h2"] containsObject:identifier])
        return random_same(0, 3, 2, 1);
    else if ([@[@"ssc_dxds_q3",@"ssc_dxds_h3"] containsObject:identifier])
        return random_same(0, 3, 3, 1);
#warning  - 不定胆-任三一码 || 任选 未定
    NSString *warning = [NSString stringWithFormat:@"时时彩随机算法没有包含->二级玩法标识符:%@",identifier];
    NSAssert(NO, warning);
    return nil;
}

+ (NSMutableArray *)getRandomArrForShiYiXuanWu:(NSString *)identifier{
    if ([@[@"s115_q2_zhi"] containsObject:identifier])
        return random_different(1, 11, 2, Arr(1, 1));//获取随机数组合，数组的集合之间不允许有重复元素
    else if ([@[@"s115_q3_zhi"] containsObject:identifier])
        return random_different(1, 11, 3, Arr_3(1,1,1));
    else if ([@[@"s11x5_q1z",@"s115_rx1",@"ssc_11x5_bdw"] containsObject:identifier])
        return random_same(1, 11, 1, 1);
    else if ([@[@"s115_q2_zu",@"s115_rx2"] containsObject:identifier])
        return random_same(1, 11, 1, 2);
    else if ([@[@"s115_q3_zu",@"s115_rx3"] containsObject:identifier])
        return random_same(1, 11, 1, 3);
    else if ([@[@"s115_rx4"] containsObject:identifier])
        return random_same(1, 11, 1, 4);
    else if ([@[@"s115_rx5"] containsObject:identifier])
        return random_same(1, 11, 1, 5);
    else if ([@[@"s115_rx6"] containsObject:identifier])
        return random_same(1, 11, 1, 6);
    else if ([@[@"s115_rx7"] containsObject:identifier])
        return random_same(1, 11, 1, 7);
    else if ([@[@"s115_rx8"] containsObject:identifier])
        return random_same(1, 11, 1, 8);
    else if ([@[@"qwwf_czw"] containsObject:identifier])
        return random_same(3, 9, 1, 1);
#warning - 11选5 定位胆玩法
    NSString *warning = [NSString stringWithFormat:@"11选5随机算法没有包含->二级玩法标识符:%@",identifier];
    NSAssert(NO, warning);
    return nil;
}

+ (NSMutableArray *)getRandomArrForPKShi:(NSString *)identifier{
    if ([@[@"bjpk10_x2"] containsObject:identifier])
        return random_different(1, 10, 2, Arr(1, 1));//获取随机数组合，数组的集合之间不允许有重复元素
    else if ([@[@"bjpk10_x3"] containsObject:identifier])
        return random_different(1, 10, 3, Arr_3(1, 1, 1));
    else if ([@[@"pk10_lm_dxds1"] containsObject:identifier])
        return random_same(0, 3, 1, 1);//获取随机数组合，数组的集合之间允许有重复元素
    else if ([@[@"pk10_lh"] containsObject:identifier])
        return random_same(0,1, 1, 1);
    else if ([@[@"pk10_x1"] containsObject:identifier])
        return random_same(1, 10, 1, 1);
#warning pk拾-定位胆
    NSString *warning = [NSString stringWithFormat:@"pk10随机算法没有包含->二级玩法标识符:%@",identifier];
    NSAssert(NO, warning);
    return nil;
}

+ (NSMutableArray *)getRandomArrForDiPinCai:(NSString *)identifier{
    if ([@[@"s3d_hz"] containsObject:identifier])
        return random_same(0, 27, 1, 1);//获取随机数组合，数组的集合之间允许有重复元素
    else if ([@[@"ssc_2x_h2f",@"three_2x_q2f"] containsObject:identifier])
        return random_same(0, 9, 2, 1);
    else if ([@[@"ssc_3x_h3f"] containsObject:identifier])
        return random_same(0, 9, 3, 1);
    else if ([@[@"ssc_5x_q3"] containsObject:identifier])
        return random_same(0, 9, 1, 1);
    else if ([@[@"ssc_z3_q3",@"ssc_2x_bdw",@"ssc_z2_f2"] containsObject:identifier])
        return random_same(0, 9, 1, 2);
    else if ([@[@"ssc_z3_q6"] containsObject:identifier])
        return random_same(0, 9, 1, 3);
    else if ([@[@"ssc_dxds_h2"] containsObject:identifier])
        return random_same(0, 3, 2, 1);
#warning 低频彩-定位胆 || 大小单双-任选大小单双
    NSString *warning = [NSString stringWithFormat:@"低频彩随机算法没有包含->二级玩法标识符:%@",identifier];
    NSAssert(NO, warning);
    return nil;
    
}
+ (NSMutableArray *)getRandomArrForKuaiSan:(NSString *)identifier{
    if ([@[@"k3_hz"] containsObject:identifier])
        return random_same(3, 18, 1, 1);//获取随机数组合，数组的集合之间允许有重复元
    else if ([@[@"k3_3tx", @"k3_3ltx"] containsObject:identifier])
        return random_same(0, 0, 1, 1);
    else if ([@[@"k3_2x"] containsObject:identifier])
        return random_same(1, 6, 1, 2);
    else if ([@[@"k3_3x"] containsObject:identifier])
        return random_same(1, 6, 1, 3);
    else if ([@[@"k3_3dx"] containsObject:identifier])//快三-三同单选
        return [self insert:random_same(1, 6, 1, 1) numCount:3];
    else if ([@[@"k3_2fx"] containsObject:identifier])//快三-二同复选
        return [self insert:random_same(1, 6, 1, 1) numCount:2];
    NSString *warning = [NSString stringWithFormat:@"快三随机算法没有包含->二级玩法标识符:%@",identifier];
    NSAssert(NO, warning);
    return nil;
}
+ (NSMutableArray *)getRandomArrForShiShiLe:(NSString *)identifier{
    if ([@[@"ssl_3x_3zxf"] containsObject:identifier])
        return random_same(0, 9, 3, 1);//获取随机数组合，数组的集合之间允许有重复元素
    else if ([@[@"ssl_3x_zxhz"] containsObject:identifier])
        return random_same(0, 27, 1, 1);
    else if ([@[@"ssl_bdw_1mbdw"] containsObject:identifier])
        return random_same(0, 9, 1, 1);
    else if ([@[@"ssl_3x_z3f",@"ssl_2x_q2zf",@"ssl_2x_h2zf",@"ssl_bdw_2mbdw"] containsObject:identifier])
        return random_same(0, 9, 1, 2);
    else if ([@[@"ssl_3x_z3hz"] containsObject:identifier])
        return random_same(1, 26, 1, 1);
    else if ([@[@"ssl_3x_z6hz"] containsObject:identifier])
        return random_same(3, 24, 1, 1);
    else if ([@[@"ssl_2x_q2zxf",@"ssl_2x_h2zxf"] containsObject:identifier])
        return random_same(0, 9, 2, 1);
    else if ([@[@"ssl_dxds_q2dxds",@"ssl_dxds_h2dxds"] containsObject:identifier])
        return random_same(0, 3, 2, 1);
#warning 时时乐-定位胆
    NSString *warning = [NSString stringWithFormat:@"快三随机算法没有包含->二级玩法标识符:%@",identifier];
    NSAssert(NO, warning);
    return nil;
}

//获取随机数组，数组的元素为集合，arrCount-->数组有多少个集合，setCount-->集合有多少个随机数--(数组当中所有的集合，随机数个数都相同)
+ (NSMutableArray *)getRandomArr:(NSUInteger)minNum max:(NSUInteger)maxNum arrCount:(NSUInteger)arrCount setCount:(NSUInteger)setCount {
    
    NSMutableArray *array = [NSMutableArray array];
    for (int i = 0; i < arrCount; i ++) {
        NSMutableSet *set = [self getRandomSet:minNum max:maxNum setCount:setCount];
        [array addObject:set];
    }
    return array;
}

//获取随机数组，数组的元素为集合，arrCount-->数组有多少个集合，setCount-->集合有多少个随机数--(数组当中所有的集合，随机数个数不相同；且数组当中，所有的随机数不重复)
+ (NSMutableArray *)getRandomArr:(NSUInteger)minNum max:(NSUInteger)maxNum arrCount:(NSUInteger)arrCount arrayOfSetCount:(NSArray *)setCount{
    
    NSMutableArray *newArray = [NSMutableArray  array];
    for (int i = 0; i < arrCount; i ++) {
        
        NSUInteger sub_setCount = [setCount[i] integerValue];//获取每个集合随机数的个数
        NSMutableSet *randomSet = [self getRandomSet:minNum max:maxNum setCount:sub_setCount];//获取随机数集合
        while ([self judgeChongFu:newArray randomSet:randomSet]){//如果新获取的随机集合，与数组当中已有的随机数，重复
            randomSet = [self getRandomSet:minNum max:maxNum setCount:sub_setCount];//重新随机数集合
        }
        [newArray addObject:randomSet];//把随机数集合存储到数组当中
    }
    return newArray;
}

//判断数组是否有重复随机数
+ (BOOL)judgeChongFu:(NSMutableArray *)array randomSet:(NSMutableSet *)set{
    
    BOOL Chongfu = NO;
    for (int i = 0; i < array.count; i++) {
        Chongfu = ([set intersectsSet:array[i]])?YES:NO;//如果set与数组的子集合，有交集，则说明重复
    }
    
    return Chongfu;
}

//获取随机集合(号码不可以重复) @{(2,3,5,6)}; setCount 为号码集合要多少个号码
+ (NSMutableSet *)getRandomSet:(NSUInteger)minNum max:(NSUInteger)maxNum setCount:(NSUInteger)setCount{
    
    NSMutableSet *set = [NSMutableSet set];
    for (int i = 0; i < setCount; i ++) {
        NSString *string = [NSString stringWithFormat:@"%lu",[self random:minNum max:maxNum]];
        [set addObject:[NSString stringWithFormat:@"%@",[self whileRunloop:string set:set min:minNum max:maxNum]]];//随机数添加到集合当中
    }
    return set;
}

+ (NSString *)whileRunloop:(NSString *)number set:(NSMutableSet *)set min:(NSUInteger)minNum max:(NSUInteger)maxNum{
    if ([set containsObject:number])
        return [self whileRunloop:[NSString stringWithFormat:@"%lu",[self random:minNum max:maxNum]] set:set min:minNum max:maxNum];
    else
        return number;
    
}
//获取一个随机整数 范围在[minNum, maxNum]
+ (NSUInteger)random:(NSUInteger)minNum max:(NSUInteger)maxNum{
    return  minNum + arc4random() % (maxNum - minNum + 1);
}

//获取一个随机整数 范围在[minNum, maxNum]，且不能包含某个数字，否则继续重新生随机整数
+ (NSUInteger)random:(NSUInteger)minNum max:(NSUInteger)maxNum notContain:(NSUInteger)notContainNum{
    NSUInteger number = (minNum + arc4random() % (maxNum - minNum + 1));
    if (number == notContainNum)
        return [self random:minNum max:maxNum notContain:notContainNum];
    else
        return  number;
}
//--------------------------------------------数据包装-------------------------------------------------------------------------------------------//
//字符串包装成字典
+ (NSMutableArray *)dictionaryWithCellArr:(NSArray *)cellArr array:(NSMutableArray *)selectNumArr{
    
    NSAssert(selectNumArr.count == cellArr.count, @"机选号码的数组元素的个数，与已有的数组元素个数不符合");
    NSMutableArray *newArr = [NSMutableArray array];
    for (int i = 0; i < cellArr.count; i ++ ) {
        [newArr addObject:@{cellArr[i]:[selectNumArr[i] allObjects]}];
    }
    return newArr;
}
//字符串包装成字典 cellArr 需要选中的随机位级数组  selectNumSet需要选中的号码集合
+ (NSArray *)dictionaryWithWeiJiArr:(NSArray *)cellArr set:(NSSet *)selectNumSet{
    
    NSMutableArray *newArr = [NSMutableArray array];
    for (int i = 0; i < cellArr.count; i ++ ) {
        NSString * string = [NSString stringWithFormat:@"%@",cellArr[i]];
        [newArr addObject:@{string:selectNumSet}];
    }
    return newArr;
}

//字符串包装成字典 cellArr 需要选中的随机位级数组  selectNumSet需要选中的号码集合
+ (NSArray *)dictionaryWithRenXuan:(NSUInteger)min max:(NSUInteger)max cellCount:(NSUInteger)cellCount minNum:(NSUInteger)minNum maxNum:(NSUInteger)maxNum numCount:(NSUInteger)numCount identifier:(NSString *)identifier{
    NSMutableArray *newArr = [NSMutableArray array];
    NSArray *cellArr  = [[self getRandomSet:min max:max setCount:cellCount] allObjects];
    NSUInteger sameRandomNum = 0;//用于快三二同单选的同号的随机数
    NSUInteger diffRandomNum = 0;//用于快三二同单选的不同号的随机数
    for (int i = 0; i < cellArr.count; i++ ) {
        NSString * string = [self replace:cellArr[i] identifier:identifier];
        if ([identifier isEqualToString:@"bjpk10_dw"]){//如果是pk10定位胆选,随机号码不足两位的，自动补0
            NSArray *array = [[self getRandomSet:minNum max:maxNum setCount:numCount] allObjects];
            NSString *number = [NSString stringWithFormat:@"%02d",[array[0] intValue]];
            [newArr addObject:@{string:[NSSet setWithObject:number]}];
        }
        if ([identifier isEqualToString:@"k3_2dx"]) {
            if ([string isEqualToString:@"同号"]){
                sameRandomNum = [self random:0 max:5 notContain:diffRandomNum];//取一个随机数，作为下标
                NSArray *sameNumArr = @[@"11",@"22",@"33",@"44",@"55",@"66"];//用随机数到同号数组中取值
                [newArr addObject:@{string:[NSSet setWithObject:sameNumArr[sameRandomNum]]}];
            }
            else if ([string isEqualToString:@"不同号"]){
               diffRandomNum = [self random:0 max:5 notContain:sameRandomNum];//取一个随机数，不同号数组的下标
                NSArray *diffNumArr = @[@"1",@"2",@"3",@"4",@"5",@"6"];//用随机数到不同号数组中取值
                [newArr addObject:@{string:[NSSet setWithObject:diffNumArr[diffRandomNum]]}];
            }
        }
        else
            [newArr addObject:@{string:[self getRandomSet:minNum max:maxNum setCount:numCount]}];
    }
    
    return newArr;
}

//换数组的title
+ (NSString *)replace:(NSString *)string identifier:(NSString *)identifier{
    if ([@[@"ssc_11x5_dwd"] containsObject:identifier]) {
        if ([string isEqualToString:@"0"])
            return @"第一位";
        else if ([string isEqualToString:@"1"])
            return @"第二位";
        else if ([string isEqualToString:@"2"])
            return @"第三位";
        else if ([string isEqualToString:@"3"])
            return @"第四位";
        else if ([string isEqualToString:@"4"])
            return @"第五位";
    }
    else if ([@[@"bjpk10_dw"] containsObject:identifier]){
        if ([string isEqualToString:@"0"])
            return @"冠军";
        else if ([string isEqualToString:@"1"])
            return @"亚军";
        else if ([string isEqualToString:@"2"])
            return @"季军";
        else if ([string isEqualToString:@"3"])
            return @"第四名";
        else if ([string isEqualToString:@"4"])
            return @"第五名";
        else if ([string isEqualToString:@"5"])
            return @"第六名";
        else if ([string isEqualToString:@"6"])
            return @"第七名";
        else if ([string isEqualToString:@"7"])
            return @"第八名";
        else if ([string isEqualToString:@"8"])
            return @"第九名";
        else if ([string isEqualToString:@"9"])
            return @"第十名";
    }
    else if ([@[@"k3_2dx"] containsObject:identifier]){
        if ([string isEqualToString:@"0"])
            return @"同号";
        else
            return @"不同号";
    }
    else{
        if ([string isEqualToString:@"0"])
            return @"万位";
        else if ([string isEqualToString:@"1"])
            return @"千位";
        else if ([string isEqualToString:@"2"])
            return @"百位";
        else if ([string isEqualToString:@"3"])
            return @"十位";
        else if ([string isEqualToString:@"4"])
            return @"个位";
    }
    return string;
}

+ (NSMutableArray *)insert:(NSMutableArray *)array numCount:(NSUInteger)numCount{
    
    for (NSSet *set in array.reverseObjectEnumerator) {
        NSMutableSet *mutableSet = [NSMutableSet set];
        for (NSString *string in  [set allObjects]) {
            if (numCount == 2)
                [mutableSet addObject:[NSString stringWithFormat:@"%@%@",string,string]];
            else if (numCount == 3)
                [mutableSet addObject:[NSString stringWithFormat:@"%@%@%@",string,string,string]];
            
        }
        [array removeObject:set];
        [array addObject:mutableSet];
    }
    return array;
}
//字典转数组
//+ (NSMutableArray *)arrayWithDict:(NSDictionary *)dict{
//
//    NSMutableArray *newArr = [NSMutableArray array];
//    NSMutableArray *array = [NSMutableArray arrayWithArray:dict[@"resource"]];
//    for (int i = 0; i < array.count; i ++) {
//        NSMutableDictionary *newDict = [NSMutableDictionary dictionary];
//        NSString *key = [array[i]valueForKey:@"title"];//获取键值对title=@"万位"的value，作为新字典的key
//        //        NSMutableSet *value = [NSMutableSet setWithObject:[array[i] valueForKey:@"randomNumArr"]];//获取键值对randomNumArr=@[@"4"]的value，作为新字典的value
//        [newDict setValue:[array[i] valueForKey:@"randomNumArr"] forKey:key];//增加键值对@"万位"= @{(@“6”)}
//        [newArr addObject:newDict];//添加到新数组中
//    }
//    return newArr;
//}
@end
